/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package OLD;

import ItineraryDays.*;
import com.sun.lwuit.Command;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.events.ActionListener;
import java.io.IOException;
import java.util.Vector;

/**
 *
 * @author Niall
 */
public class Menu_Manager {

    Vector menus = new Vector();
    Vector menus_2 = new Vector();
    int counter = 0;
    public String curr_menu = "Main Menu";
    Command exitCommand = new Command("Exit");
    Command backCommand = new Command("Back");

    public Menu_Manager(ActionListener a) {
        buildMenus(a);

        get("Main Menu").run();

    }

    public void buildMenus(ActionListener a) {

        menus.addElement(new MainMenu(a));
        menus.addElement(new Map(a));
        menus.addElement(new Translator(a));
        menus.addElement(new Landmarks(a));
        menus.addElement(new Currency(a));
        menus.addElement(new Camera(a));
        //added for savage
        menus.addElement(new Itinerary(a));
        menus.addElement(new ItinMon(a));
        menus.addElement(new ItinTue(a));
        menus.addElement(new ItinWed(a));
        menus.addElement(new ItinThu(a));
        menus.addElement(new ItinFri(a));
        menus.addElement(new ItinSat(a));
        menus.addElement(new ItinSun(a));


    }

    public void Update() {

        get(curr_menu).update();

    }

    public Menu getCurrentMenu() {
        return get(curr_menu);
    }

    public Form getCurrent() {
        return get(curr_menu).getForm();

    }

    public boolean setForm(String Name) {
        return getCurrentMenu().setList(Name);
    }

    public Menu get(String Name) {
        for (int i = 0; i < menus.size(); i++) {
            Menu curr = ((Menu) menus.elementAt(i));
            if (curr.name.equalsIgnoreCase(Name)) {
                return curr;
            }
        }
        return null;

    }

    public void setMenu(String Name) {

        get(curr_menu).delete();

        if (Name.equalsIgnoreCase("Camera")) {
            ((Camera) get(Name)).start();
        }
        if (curr_menu.equalsIgnoreCase("Camera")) {
            ((Camera) get(curr_menu)).stop();
        }
        Menu m = get(Name);
        if (m != null) {
            m.run();
        } else {
            if (get(curr_menu).setList(Name)) {
            } else {
                System.out.println("reader Menu");
                buildReaderMenu(Name);
            }
        }
        curr_menu = Name;
    }

    public void buildReaderMenu(String fileName) {
        if (get(curr_menu) != null) {
            get(curr_menu).delete();
        }
        Menu m = new Reader(fileName, "", ((Menu) menus.elementAt(0)).a);
        Form f = new Form(fileName);
        f.setCommandListener(m.a);
        f.setTitle(m.name);
        m.setTransition(f, 1);
        if (m.backround != "") {
            try {
                f.setBgImage(Image.createImage("/images/" + m.backround));
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        m.setLayout(f, m.layoutType);
        m.addComponents(f);
        menus.addElement(m);
        curr_menu = fileName;
        f.show();
        System.gc();



    }
}
